import cv2
import numpy as np

img = cv2.imread("./img/logo.png")
# 获取图像高度、宽度
h, w, c = img.shape
# 纯黑的单通道图
red_mask = np.zeros((h, w)).astype(np.uint8)
blue_mask = np.zeros((h, w)).astype(np.uint8)
green_mask = np.zeros((h, w)).astype(np.uint8)
# 通过循环方式对像素进行更改
for i in range(h):
    for j in range(w):
        # 判断所有的像素中是否包含红色像素
        if 0 <= img[i, j, 0] <= 10 and 0 <= img[i, j, 1] <= 10 and img[i, j, 2] > 200:
            red_mask[i, j] = 255
        if 0 <= img[i, j, 2] <= 10 and 0 <= img[i, j, 1] <= 10 and img[i, j, 0] > 200:
            blue_mask[i, j] = 255
        if 0 <= img[i, j, 0] <= 10 and 0 <= img[i, j, 2] <= 10 and img[i, j, 1] > 200:
            green_mask[i, j] = 255
# 判断是否有红色像素
if np.sum(red_mask == 255) > 0:
    print("该图存在红色像素")
if np.sum(green_mask == 255) > 0:
    print("该图存在绿色像素")
if np.sum(blue_mask == 255) > 0:
    print("该图存在蓝色像素")

# cv2.imshow("black", black)
# cv2.waitKey(0)
